<template>
  <div id="topSearch">
    <div class="search-box">
      <el-form
        :inline="true"
        :model="searchInfo"
        ref="ruleForm"
        class="demo-form-inline"
      >
        <el-form-item label="商品名称" prop="name">
          <el-input
            size="small"
            v-model="searchInfo.name"
            placeholder="请您输入商品名称"
            maxlength="100"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="商品类型" prop="type">
          <el-select size="small" v-model="searchInfo.type" clearable>
            <el-option
              v-for="(item, index) in goodsTypeList"
              :key="index"
              :label="item.dictLabel"
              :value="item.dictValue"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="兑换时间" prop="exchangeTime">
          <el-date-picker
            size="small"
            v-model="searchInfo.exchangeTime"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
            value-format="timestamp"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="大鹏号" prop="dpAccount">
          <el-input
            size="small"
            v-model="searchInfo.dpAccount"
            placeholder="请您输入大鹏号"
            maxlength="100"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item class="s-btn">
          <el-button type="success" icon="el-icon-search" @click="toSearch">
            查询
          </el-button>
          <el-button type="success" plain @click="resetForm('ruleForm')">
            重置
          </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>
<script>
import { sysNormalDisable } from '@utils/dictionariesFunc'
export default {
  data() {
    return {
      searchInfo: {
        name: '', //商品名称
        type: '', //商品类型
        startTime: '', //开始时间
        endTime: '', //结束时间
        dpAccount: '', //大鹏号
        exchangeTime: [] //兑换时间
      },
      goodsTypeList: [{ dictLabel: '全部', dictValue: '' }]
    }
  },
  watch: {
    'searchInfo.exchangeTime': {
      handler(val) {
        this.searchInfo.startTime = val && val.length ? val[0] : ''
        this.searchInfo.endTime = val && val.length ? val[1] : ''
      },
      deep: true
    }
  },
  async mounted() {
    const { goodsTypeList } = this
    this.goodsTypeList = goodsTypeList.concat(
      await sysNormalDisable('Integral_commodity_type')
    )
  },
  methods: {
    toSearch() {
      const obj = Object.assign({}, this.searchInfo)
      delete obj.exchangeTime
      this.$emit('toSearch', obj)
    },
    resetForm(formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>
<style lang="less" scoped></style>
